<template>
  <div class="news">
    <!-- 导航区域 -->
    <ul>
      <li v-for="news in newsList" :key="news.id">
        <button @click="tiao(news)">查看新闻</button>
        <RouterLink :to="{
          name: 'xiang',
          query: {
            id: news.id,
            title: news.title,
            content: news.content,
          }
        }">
          {{ news.title }}
        </RouterLink>
      </li>
    </ul>
    <!-- 展示区 -->
    <div class="news">
      <RouterView></RouterView> <!-- 不用引入 直接使用 占位 -->
    </div>
    <a></a>
  </div>
</template>

<script setup lang="ts" name="News">
import {reactive} from 'vue'
import {useRouter} from 'vue-router'
const router = useRouter()
// ---------------------数据---------------------------
const newsList = [
{id: '1', title: '标题1', content: '看看你的，好吗?'},
{id: '2', title: '标题2', content: '好好学习'},
{id: '3', title: '标题3', content: '天天向上'},
{id: '4', title: '标题4', content: '放假啦 啊哈哈哈'}
]

//-------------------接口---------------------
interface NewsInter {
  id: string,
  title: string,
  content: string
}


//---------------------函数------------------------
function tiao(news:NewsInter) { // news后面加上 :NewsInter 限制里面的变量 也可以加上 :any 表示随意
  // console.log(news);
  router.push({
    name: 'xiang', // 你要指出来 跳到哪里
    query: {
      id: news.id,
      title: news.title,
      content: news.content,
    }
  })
}

</script>

<style scoped>
/* 新闻 */
.news {
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  height: 100%;
}
.news li {
  color: green 
}
.news ul {
  margin-top: 30px;
  /* list-style: none; */
  padding-left: 10px;
}

.news li>a {
  font-size: 18px;
  line-height: 40px;
  text-decoration: none;
  color: #64967E;
  text-shadow: 0 0 1px rgb(0, 84, 0);
}

.news-content {
  width: 70%;
  height: 90%;
  border: 1px solid;
  margin-top: 20px;
  border-radius: 10px;
}
</style>